<template>
  <loading-wrap>
    <div class="card">
      <div class="card-body">
        <div class="d-flex mb-3">
          <h5 class="card-title">企业基本信息</h5>
          <button
            v-if="customerData.project_status === '0' || customerData.project_status === '2'"
            class="btn pt-0 btn-text text-muted"
            @click="edit()"
          >
            <i class="fa fa-edit"></i>
          </button>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">借款主体名称：</div>
          <div class="dl-dd">{{ customerInfo.load_main_entity || '-' }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">企业名称：</div>
          <div class="dl-dd">{{ relatedData.customer_name || '-' }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">统一社会信用代码：</div>
          <div class="dl-dd">{{ relatedData.register_no || '-' }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">经营许可证号：</div>
          <div class="dl-dd">{{ baseData.licence_no || '-' }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">注册资金：</div>
          <div class="dl-dd">{{ baseData.register_funds || '-' }} 万元</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">实收资本：</div>
          <div class="dl-dd">{{ baseData.capital_coll || '-' }} 万元</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">成立日期：</div>
          <div class="dl-dd">{{ $utils.dateFormat(baseData.established_date, 'yyyy.MM.dd') }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">经营年限：</div>
          <div class="dl-dd">{{ baseData.bussiness_years || '-' }} 年</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">企业地址：</div>
          <div class="dl-dd">{{ relatedData.address || '-' }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">经营范围：</div>
          <div class="dl-dd">{{ baseData.bussiness_scope || '-' }}</div>
        </div>
        <div class="dl-wrap">
          <div class="dl-dt">企业荣誉描述：</div>
          <div class="dl-dd">{{ baseData.en_honor_des || '-' }}</div>
        </div>
        <div class="dl-wrap">
          <div class="dl-dt">知识产权及经营许可：</div>
          <div class="dl-dd">{{ baseData.intellectual_property_des || '-' }}</div>
        </div>
        <!--<div class="dl-wrap">-->
        <!--<div class="dl-dt">法人姓名：</div>-->
        <!--<div class="dl-dd">{{relatedData.corp_name}}</div>-->
        <!--</div>-->

        <!--<div class="dl-wrap">-->
        <!--<div class="dl-dt">电话：</div>-->
        <!--<div class="dl-dd">{{relatedData.mobile_no}}</div>-->
        <!--</div>-->
        <div class="dl-wrap">
          <div class="dl-dt">企业类型：</div>
          <div class="dl-dd">{{ enumFarmType[relatedData.farm_type] || '-' }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">农场类型：</div>
          <div class="dl-dd">{{ relatedData.org_class_name || '-' }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">申请贷款金额：</div>
          <div class="dl-dd">{{ relatedData.apply_funds | pureUnit('万元') }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">贷款年限：</div>
          <div class="dl-dd">{{ relatedData.load_years | pureUnit('年') }}</div>
        </div>
        <div class="dl-wrap">
          <div class="dl-dt">申请资金用途：</div>
          <div class="dl-dd">{{ relatedData.funds_use_dir || '-' }}</div>
        </div>
        <div class="dl-wrap">
          <div class="dl-dt">投资总金额：</div>
          <div class="dl-dd">{{ relatedData.invest_total | pureUnit('万元') }}</div>
        </div>
        <div class="dl-wrap">
          <div class="dl-dt">已投入资金（自有）：</div>
          <div class="dl-dd">{{ relatedData.invest_self | pureUnit('万元') }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">近一年收入：</div>
          <div class="dl-dd">{{ relatedData.last_year_income }}</div>
        </div>
        <div class="dl-wrap">
          <div class="dl-dt">近一年利润：</div>
          <div class="dl-dd">{{ relatedData.last_year_profit }}</div>
        </div>
        <div class="dl-wrap">
          <div class="dl-dt">企业负债：</div>
          <div class="dl-dd">{{ relatedData.en_debt }}</div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">是否禁入：</div>
          <div class="dl-dd">
            <span>
              <i v-if="baseData.is_debar === '1'" class="fa fa-check" style="color: #42bd56"></i>
              <i v-else class="fa fa-close"></i>
            </span>
          </div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">知识产权数量：</div>
          <div class="dl-dd">
            {{ baseData.intellectual_property_num }}
          </div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">统一社会信用代码：</div>
          <div class="dl-dd">
            <span>
              <i
                v-if="baseData.is_have_bussiness_license === '1'"
                class="fa fa-check"
                style="color: #42bd56"
              ></i>
              <i v-else class="fa fa-close"></i>
            </span>
          </div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">公司章程：</div>
          <div class="dl-dd">
            <span>
              <i
                v-if="baseData.is_have_com_policy === '1'"
                class="fa fa-check"
                style="color: #42bd56"
              ></i>
              <i v-else class="fa fa-close"></i>
            </span>
          </div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">工商公示报告：</div>
          <div class="dl-dd">
            <span>
              <i
                v-if="baseData.is_have_buss_public === '1'"
                class="fa fa-check"
                style="color: #42bd56"
              ></i>
              <i v-else class="fa fa-close"></i>
            </span>
          </div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">经营许可证：</div>
          <div class="dl-dd">
            <span>
              <i
                v-if="baseData.is_have_licence_no === '1'"
                class="fa fa-check"
                style="color: #42bd56"
              ></i>
              <i v-else class="fa fa-close"></i>
            </span>
          </div>
        </div>

        <div class="dl-wrap">
          <div class="dl-dt">企业荣誉：</div>
          <div class="dl-dd">
            <span>
              <i
                v-if="baseData.is_have_honor === '1'"
                class="fa fa-check"
                style="color: #42bd56"
              ></i>
              <i v-else class="fa fa-close"></i>
            </span>
          </div>
        </div>

        <div class="dl-wrap mt-5">
          <div class="dl-dt"></div>
          <div class="dl-dd">
            <button
              v-if="customerData.project_status === '0' || customerData.project_status === '2'"
              class="btn btn-primary"
              @click="edit()"
            >
              <i class="fa fa-edit"></i>
              修改
            </button>
          </div>
        </div>
      </div>
    </div>

    <form-component
      ref="fc"
      :auto-init="false"
      :before-save="releteSave"
      :form-data="formData"
      :table-data="customerInfo"
      :table-id="tableId"
      :table-name="tableName"
      :visible.sync="editVisible"
      @success="getRelatedData"
    ></form-component>
  </loading-wrap>
</template>
<script>
import FormComponent from '@/components/FormComponent'
import { enumFarmType, enumMarketDistanceType } from '@/credit/plugins/enum'

export default {
  components: {
    FormComponent,
  },
  props: {},
  data() {
    return {
      enumFarmType,
      id: '',
      relatedData: {},
      baseData: {},
      customerInfo: {},
      emptyText: '<i class="fa fa-times text-muted"></i>',
      editVisible: false,
      tableName: 'datum_customer_info',
      formData: {
        load_main_entity: { type: 'text', label: '借款主体名称', value: '', required: true },
        customer_name: {
          type: 'text',
          label: '企业名称',
          value: '',
          required: true,
          disabled: true,
        },
        register_no: {
          type: 'text',
          label: '统一社会信用代码',
          value: '',
          required: true,
          disabled: true,
        },
        // org_class_name: { type: 'text', label: '农场类型', value: '', required: true, disabled: true },
        farm_type: {
          type: 'radio',
          label: '企业类型',
          value: '',
          required: true,
          inline: true,
          enumType: enumFarmType,
        },
        address_detail: { type: 'text', label: '详细地址', value: '', disabled: true },
        established_date: { type: 'date', label: '成立日期', value: '' },
        register_funds: { type: 'number', label: '注册资金', value: '', unit: '万元', step: 1 },
        capital_coll: { type: 'number', label: '实收资本', value: '', unit: '万元', step: 1 },
        licence_no: { type: 'text', label: '经营许可编号', value: '' },
        bussiness_years: { type: 'number', label: '经营年限', value: '', unit: '年', step: 1 },
        mobile_no: { type: 'text', label: '办公室电话', value: '' },
        bussiness_scope: { type: 'textarea', label: '经营范围', value: '' },
        en_honor_des: { type: 'textarea', label: '企业荣誉描述', value: '' },
        intellectual_property_des: { type: 'textarea', label: '知识产权及经营许可', value: '' },
        intellectual_property_num: { type: 'number', label: '知识产权数量', value: '', step: 1 },
        market_distance_type: {
          type: 'radio',
          label: '离加工消费市场距离',
          value: '',
          inline: true,
          enumType: enumMarketDistanceType,
        },
        apply_funds: {
          type: 'number',
          label: '申请贷款金额',
          value: '',
          step: 1,
          redun: true,
          unit: '万元',
        },
        load_years: {
          type: 'number',
          label: '贷款年限',
          value: '',
          step: 1,
          redun: true,
          unit: '年',
        },
        funds_use_dir: { type: 'text', label: '申请资金用途', value: '', redun: true },
        invest_total: {
          type: 'number',
          label: '投资总金额',
          value: '',
          step: 0.01,
          redun: true,
          unit: '万元',
        },
        invest_self: {
          type: 'number',
          label: '已投入资金（自有）',
          value: '',
          step: 0.01,
          redun: true,
          unit: '万元',
        },

        last_year_income: {
          type: 'number',
          label: '近一年收入',
          value: '',
          step: 0.01,
          redun: true,
          unit: '万元',
        },
        last_year_profit: {
          type: 'number',
          label: '近一年利润',
          value: '',
          step: 0.01,
          redun: true,
          unit: '万元',
        },
        en_debt: {
          type: 'number',
          label: '企业负债',
          value: '',
          step: 0.01,
          redun: true,
          unit: '万元',
        },
        is_debar: {
          type: 'radio',
          label: '是否禁入',
          value: 0,
          inline: true,
          enumType: { 0: '否', 1: '是' },
        },
        is_match_policy: {
          type: 'radio',
          label: '是否符合政策导向',
          value: 1,
          inline: true,
          enumType: { 1: '是', 0: '否' },
        },
        is_have_bussiness_license: {
          type: 'radio',
          label: '是否有营业执照',
          value: 0,
          inline: true,
          enumType: { 1: '有', 0: '无' },
        },
        is_have_com_policy: {
          type: 'radio',
          label: '是否有公司章程',
          value: 0,
          inline: true,
          enumType: { 1: '有', 0: '无' },
        },
        is_have_buss_public: {
          type: 'radio',
          label: '是否有工商公示报告',
          value: 0,
          inline: true,
          enumType: { 1: '有', 0: '无' },
        },
        is_have_licence_no: {
          type: 'radio',
          label: '是否有经营许可证',
          value: 0,
          inline: true,
          enumType: { 1: '有', 0: '无' },
        },
        is_have_honor: {
          type: 'radio',
          label: '有无企业荣誉',
          value: 0,
          inline: true,
          enumType: { 1: '有', 0: '无' },
        },
      },
      tableId: '',
    }
  },
  computed: {},
  watch: {},
  created() {
    this.id = this.$route.query.id || sessionStorage.getItem('customer_related_id')
    this.customerData = JSON.parse(sessionStorage.getItem('customer_related_view'))
    this.getRelatedData()
  },
  mounted() {},
  methods: {
    releteSave() {
      const ref = this.$refs.fc
      let data = {}
      data.apply_funds = ref.formList.apply_funds.value
      data.load_years = ref.formList.load_years.value
      data.funds_use_dir = ref.formList.funds_use_dir.value
      data.invest_total = ref.formList.invest_total.value
      data.invest_self = ref.formList.invest_self.value

      data.last_year_income = ref.formList.last_year_income.value
      data.last_year_profit = ref.formList.last_year_profit.value
      data.en_debt = ref.formList.en_debt.value
      this.$api.updateData('credit', 'customer_related', this.id, data)
      return null
    },

    getRelatedData() {
      this.$api
        .getData(
          'credit',
          'customer_related_base_view',
          {
            'customer_related_id.eq': this.id,
          },
          { create_time: 'desc' }
        )
        .then(res => {
          if (!res.data || !res.data.length) {
            return
          }
          this.relatedData = res.data[0]
          this.getCustomerInfo()
        })
    },

    getCustomerInfo() {
      this.$api
        .getData('credit', 'datum_customer_info', {
          'customer_related_id.eq': this.id,
        })
        .then(res => {
          if (!res.data || !res.data.length) {
            return
          }
          this.customerInfo = res.data[0]
          this.baseData = { ...this.customerInfo }
          this.tableId = this.customerInfo.id
        })
    },

    edit() {
      this.customerInfo.customer_name = this.relatedData.customer_name
      this.customerInfo.address_detail = this.relatedData.address
      this.customerInfo.apply_funds = this.relatedData.apply_funds
      this.customerInfo.load_years = this.relatedData.load_years
      this.customerInfo.funds_use_dir = this.relatedData.funds_use_dir
      this.customerInfo.invest_total = this.relatedData.invest_total
      this.customerInfo.invest_self = this.relatedData.invest_self

      this.customerInfo.last_year_income = this.relatedData.last_year_income
      this.customerInfo.last_year_profit = this.relatedData.last_year_profit
      this.customerInfo.en_debt = this.relatedData.en_debt
      this.customerInfo.farm_type = this.relatedData.farm_type
      if (!this.customerInfo.load_main_entity) {
        this.customerInfo.load_main_entity = this.relatedData.customer_name
      }

      this.editVisible = true
    },
  },
}
</script>
<style scoped lang="scss"></style>
